package models

import (
	"gorm.io/gorm"
	"zk1/common/mysql"
)

type User struct {
	gorm.Model
	Mobile   string `gorm:"type:char(11);not null;comment:手机号"`
	Code     string `gorm:"type:char(32);not null;comment:验证码"`
	Picture  string `gorm:"type:varchar(255);not null;comment:头像"`
	NickName string `gorm:"type:varchar(20);not null;comment:昵称"`
}

func (u *User) SendSms() error {
	return mysql.Db.Model(User{}).Create(&u).Error
}

func RegisterLogin(mobile, code string) (u *User, err error) {
	err = mysql.Db.Model(User{}).Where("mobile = ?", mobile).Where("code = ?", code).First(&u).Error
	return
}

func HomePage(mobile, code string) (u *User, err error) {
	err = mysql.Db.Model(User{}).Where("mobile = ?", mobile).Where("code = ?", code).First(&u).Error
	return
}

type Taxi struct {
	gorm.Model
	UserId      int64  `gorm:"type:int(11);not null;comment:用户ID"`
	Destination string `gorm:"type:varchar(50);not null;comment:目的地"`
}

func (t *Taxi) Create() error {
	return mysql.Db.Model(Taxi{}).Create(&t).Error
}

func Update(destination string) (t *Taxi, err error) {
	err = mysql.Db.Model(Taxi{}).Update("destination = ?", destination).Error
	return
}
